package cn.smart.epic.common.warpper;

import com.alibaba.fastjson.JSONObject;

import java.util.List;

/**
 * @Auther Uncle_Z
 * @date 2018/6/13 11:01
 * @Email:2545375@qq.com
 * @Descrition 控制器查询结果的包装类基类
 * @since 1.0
 */

public abstract class BaseControllerWarpper {

    public Object obj =null;

    public BaseControllerWarpper(Object obj){
        this.obj=obj;
    }

    public Object warp() {
        if (this.obj instanceof List) {
            List<JSONObject> list = (List<JSONObject>) this.obj;
            list.forEach(map -> warpTheMap(map));
            return list;
        } else if (this.obj instanceof JSONObject) {
            JSONObject map = (JSONObject) this.obj;
            warpTheMap(map);
            return map;
        } else {
            return this.obj;
        }
    }

    protected abstract void warpTheMap(JSONObject map);
}
